<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function execCode(counter, successCallback, failCallback) {
      setTimeout(function () {
        if (counter > 0) {
          let total = 0
          for (let i = 0; i < counter; i++) {
            total += i
          }
          // 在某一个时刻,只需要回调我们传入的函数
          callback(total)
        } else {
          failCallback(`${counter}值有问题`)
        }
      }, 3000);
    }

    execCode(100, (value) => {
      console.log('外界监听到汉堡已经做好了:', value)
    }, (err) => {
      console.log('外界监听到汉堡做失败了:',err)
    })
  </script>
</body>

</html>